{% extends 'wanplus/../wanba.general/base_frame.html' %}
{% load staticfiles %}
{% block title %}
  玩吧APK更新-Angle
{% endblock %}
{% block css %}
  <link rel="stylesheet" rev="stylesheet" href="{% static 'wanplus/css/wanplus.css' %}" />
{% endblock %}
{% block body %}
  <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container col-lg-offset-2 col-sm-offset-2 col-xs-offset-2 col-md-offset-2
          col-lg-8 col-md-8 col-sm-8 col-xs-8">
      <div class="navbar-header">
        <a class="navbar-brand">玩吧APK更新-Angle</a>
      </div>
    </div>
  </nav>
  <div id="wb-upgrader-main">
    <div class="row">
      <div class="container col-lg-offset-2 col-sm-offset-2 col-xs-offset-2 col-md-offset-2
          col-lg-8 col-md-8 col-sm-8 col-xs-8">
        <p>选择要上传的APK包</p>
        <div id="wb-upgrader-input-form">

        </div>
      </div>
    </div>
  </div>
{% endblock %}
{% block jsimport %}
  <script type="text/javascript" src="{% static 'utils/dmuploader.js' %}"></script>
{% endblock %}
{% block jsscript %}
  <script type="text/javascript">
    $(document).ready(function(e) {
      var inputForm = $("#wb-upgrader-input-form");

      var inputFields = [];

      var insertInputField = function(container) {
        var position = inputFields.length;
        var row = $("<div />").addClass("row");
        var formGroup = $("<div />").addClass("form-group col-lg-6 col-md-6 col-sm-6 col-xs-6");
        var input = $("<input />").attr(
            {
              "type": "file"
            })
            .addClass("form-control")
            .focus(function(e) {
              var alive = $(this).data("alive");
              if (!alive) {
                $(this).data("alive", true);
                insertInputField(container);
              }
            })
            .change(function(e) {
              removeButton.show();
            });
        input.data("alive", false);

        var hintDiv = $("<div />").addClass("col-lg-6 col-md-6 col-sm-6 col-xs-6");
        var removeButton = $("<span />").addClass("fa fa-minus-circle fa-2x");
        removeButton.click(function(e) {
          removeInputField(container, row);
        });
        removeButton.hide();
        hintDiv.append(removeButton);
        row.append(formGroup);
        row.append(hintDiv);
        formGroup.append(input);
        $(container).append(row);
        inputFields.push(row);
      };

      var removeInputField = function(container, item) {
        if (item === undefined) {
          return;
        }

        item.remove();

        for (var index in inputFields) {
          var it = inputFields[index];
          if (it == item) {
            inputFields.splice(index, 1);
            break;
          }
        }
      };

      var init = function() {
        insertInputField(inputForm);
      };

      init();
    });
  </script>
{% endblock %}